import { Router, Route, Switch, Redirect } from 'react-router-dom'
import React, { Suspense } from 'react'

import AuthRoute from 'components/AuthRoute'
import history from 'utils/history'
// import Layout from './pages/Layout/index'
// import Login from './pages/Login/index'

const Layout = React.lazy(() => import('./pages/Layout/index'))
const Login = React.lazy(() => import('./pages/Login/index'))
function App() {
  return (
    <Router history={history}>
      <div className="App">
        <Suspense
          fallback={
            <div style={{ textAlign: 'center', marginTop: 200 }}>
              拼命加载中...
            </div>
          }
        >
          <Switch>
            <Redirect exact from="/" to="/login"></Redirect>
            <AuthRoute path="/home" component={Layout}></AuthRoute>
            {/* 默认情况，只有被Route处理过的组件，才能拿到 this.props.history/location/match */}
            <Route path="/login" component={Login}></Route>
          </Switch>
        </Suspense>
      </div>
    </Router>
  )
}

export default App
